// Learn cc.Class:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/class.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/class.html
// Learn Attribute:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/reference/attributes.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - [Chinese] http://docs.cocos.com/creator/manual/zh/scripting/life-cycle-callbacks.html
//  - [English] http://www.cocos2d-x.org/docs/creator/en/scripting/life-cycle-callbacks.html
/**
 * 提现
 */
let base = require("panelBase")
let viewConfig = {
    btn_back:{
        node:null,
        name:"btn_back",
        eventType:"click",
        cb:"onBtnBackClick"
    },
    btn_txDetail:{
        node:null,
        name:"btn_tx_record",
        eventType:"click",
        cb:"onBtnTxdetailClick",
    },
    //红包广告上面的激活按钮
    btn_active:{
        node:null,
        name:"tx_hb/btn_active",
        eventType:"click",
        cb:"onBtnActiveClick",
    },
    //红包广告里面的数值
    tx_hb:{
        node:null,
        name:"tx_hb/num",
    },

    //微信
    btn_wc:{
        node:null,
        name:"tx_weichat",
        eventType:"click",
        cb:"onBtnWcClick"
    },
    //余额相关
    btn_que:{
        node:null,
        name:"tx_ye/tx_que",
        eventType:"click",
        cb:"onBtnQuestionClick",
    },
    btn_hb:{
        node:null,
        name:"tx_ye/tx_hb",
        eventType:"click",
        cb:"onBtnHBClick",
    },
    tx_yue:{
        node:null,
        name:"tx_ye/yue"
    },
    //红包下面显示的内容
    btn_hb_con:{
        node:null,
        name:"tx_ye/tx_hb/con",
    },
    //快速提现相关
    // 快速提现说明
    kstx_des:{
        node:null,
        name:"tx_kstx/tx_des/content",
    },
    btn_sign:{
        node:null,
        name:"tx_kstx/tx_des/btn_sign",
        eventType:"click",
        cb:"onBtnSignClick",
    },
    togParent:{
        node:null,
        name:"tx_kstx/togContainer"
    },

};
cc.Class({
    extends: base,

    properties: {
        togList:{
            default:[],
            type:cc.Node,
        },

        selectIndex:0,
    },

    init(){
        this._super(viewConfig);
        let togParent = viewConfig["togParent"].node;
        for(let key in togParent.children)
        {
            let child = togParent.children[key];
            child.on("toggle",this.onToggle,this);
        }
        this.isInited = true;
        this.onHide();
    },

    onShow(){
        this._super();

        this.updateInfo(viewConfig["tx_yue"].node,cc.tg.cakeRoom.accMoney);
        let str = `连续签到5天即可获得一次1元提现资格 \n提现后可重新获得提现机会 \n您已连续签到${cc.tg.cakeRoom.accContinuousSign}天`;
        this.updateInfo(viewConfig["kstx_des"].node,str,cc.Label);
    },

    onBtnBackClick(){
        this.onHide();
    },
    //点击微信
    onBtnWcClick(){
       // cc.log("提现到微信")
       if(cc.sys.isBrowser)
       {
            let num = cc.tg.cakeRoom.localTxList[this.selectIndex];
            if(!num)
            {
                num = cc.tg.cakeRoom.accMoney;
            }
            else if(num > cc.tg.cakeRoom.accMoney)
            {
                cc.log("tx失败");
            }
            cc.tg.gameLogic.txToWx(num);
       }
       else
       {

       }
    },
    //提现记录
    onBtnTxdetailClick(){
        //cc.log("onclick record");
        
        cc.tg.eventCenter.dispatchEvent("showPanel",{panelName:"txDetail",active:true});
        this.onHide();
    },
    // 点击问号
    onBtnQuestionClick(){
        cc.log("on click question");
    },
    // 点击红包
    onBtnHBClick(){
        cc.log("on click hb");
    },
    //点击签到
    onBtnSignClick(){
        cc.log("on click  sign");
        cc.tg.eventCenter.dispatchEvent("showPanel",{panelName:"sign",active:true});
        this.onHide();
    },

    onBtnActiveClick(){
        cc.log("on click active ");
    },

    onToggle(e){
        let name = e.target.parent.name;
        let index = parseInt(name);
        this.selectIndex = index;
        let des = viewConfig["kstx_des"].node.parent;
        if(index == 0)
        {
            des.active = true;
        }
        else
        {
            des.active = false;
        }
        //cc.log(index);
    },


    onDestroy(){
        for(let key in viewConfig)
        {
            viewConfig[key].node = null;
        }
    },
});
